﻿@model OT.Data.User
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>@ViewBag.Title - Admin</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Charisma, a fully featured, responsive, HTML5, Bootstrap admin template.">
    <meta name="author" content="Muhammad Usman">
    <link rel="shortcut icon" href="~/Images/ot.jpg">
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
</head>
<body>
    @using (Html.BeginForm())
    {
        <div class="admin-form">
            <div class="container">
                @Html.ValidationSummary(true)
                <div class="row">
                    <div class="col-md-12">
                        <div id="divMsgIndex"></div>
                        <div class="widget worange">
                            <div class="widget-head">
                                <i class="fa fa-lock"></i>Login 
                            </div>
                            <div class="widget-content">
                                <div class="padd">
                                    <div class="form-horizontal">
                                        <div class="form-group">
                                            <label class="control-label col-lg-3" for="inputEmail">Email</label>
                                            <div class="col-lg-9">
                                                @Html.TextBoxFor(u => u.EmailAddress, new { @class = "form-control", placeholder = "Email" })
                                                @Html.ValidationMessageFor(u => u.EmailAddress)
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-lg-3" for="inputPassword">Password</label>
                                            <div class="col-lg-9">
                                                @Html.PasswordFor(u => u.Password, new { @class = "form-control", placeholder = "Password" })
                                                @Html.ValidationMessageFor(u => u.Password)
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-lg-9 col-lg-offset-3">
                                                <div class="checkbox">
                                                    <label>
                                                        <input type="checkbox">
                                                        Remember me
                                                    </label>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="widget-foot">
                                <button id="btnlogin" class="btn btn-primary">Login</button>
                                <button type="reset" class="btn btn-default btn-sm">Reset</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    }
</body>
</html>
<script type="text/javascript">
    $("#btnlogin").click(function (e) {
        var EmailID = btoa($("#EmailAddress").val());
        var Password = btoa($("#Password").val());
        var UserTypeID = $('input[name="UserTypeID"]:checked').val();
        e.preventDefault();
        if (EmailID == '' || Password == '') {
            showMsg('divMsgIndex', 'Must Be Enter EmailID and PassWord', 'danger');
        }
        else {
            $.ajax({
                url: "/Admin/Login?EmailAddress=" + EmailID + "&Password=" + Password,
                type: "POST",
                success: function (result) {
                    debugger;
                    if (result != "") {
                        if (result == "Admin") {
                            window.location = "./";
                        }
                        else {
                            showMsg('divMsgIndex', result, 'danger');
                        }
                    }
                    else {
                        showMsg('divMsgIndex', result, 'danger');
                    }
                },
                error: function (data) {
                }
            });
        }
    });
    function showMsg(controlID, Message, TypeOfMsg, width) {
        width = typeof width !== 'undefined' ? width : '100%';
        switch (TypeOfMsg) {
            case 'info':
                $('#' + controlID).css({ "width": width });
                $('#' + controlID).html(Message);
                $('#' + controlID).removeClass('alert alert-warning');
                $('#' + controlID).removeClass('alert alert-success');
                $('#' + controlID).removeClass('alert alert-danger');
                $('#' + controlID).addClass('alert alert-info');
                break;
            case 'warning':
                $('#' + controlID).css({ "width": width });
                $('#' + controlID).html(Message);
                $('#' + controlID).removeClass('alert alert-info');
                $('#' + controlID).removeClass('alert alert-success');
                $('#' + controlID).removeClass('alert alert-danger');
                $('#' + controlID).addClass('alert alert-warning');
                break;
            case 'success':
                $('#' + controlID).css({ "width": width });
                $('#' + controlID).html(Message);
                $('#' + controlID).removeClass('alert alert-info');
                $('#' + controlID).removeClass('alert alert-warning');
                $('#' + controlID).removeClass('alert alert-danger');
                $('#' + controlID).addClass('alert alert-success');
                break;
            case 'danger':
                $('#' + controlID).css({ "width": width });
                $('#' + controlID).html(Message);
                $('#' + controlID).removeClass('alert alert-info');
                $('#' + controlID).removeClass('alert alert-warning');
                $('#' + controlID).removeClass('alert alert-success');
                $('#' + controlID).addClass('alert alert-danger');
                break;
            default:
                $('#' + controlID).html('');
                $('#' + controlID).removeClass();
        }
    }
</script>
